package com.sunday.scoremanager.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.sunday.scoremanager.R;
import com.sunday.scoremanager.entity.Member;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by 刘涛 on 2017/11/16.
 */

public class ShopListAdapter extends BaseAdapter {

    private Context mContext;
    private List<Member> dataSet;

    public ShopListAdapter(Context context, List<Member> dataSet) {
        this.mContext = context;
        this.dataSet = dataSet;
    }

    @Override
    public int getCount() {
        return dataSet.size();
    }

    @Override
    public Object getItem(int position) {
        return getItem(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.list_shop_item,null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        Member item=dataSet.get(position);
        Glide.with(mContext).load(item.getLogo())
                .error(R.mipmap.ic_default)
                .into(viewHolder.shopImg);
        viewHolder.shopName.setText(item.getShopName());
        viewHolder.shopAddr.setText("地址" + item.getAddress());
        return convertView;
    }


    static class ViewHolder {
        @Bind(R.id.shop_img)
        ImageView shopImg;
        @Bind(R.id.shop_name)
        TextView shopName;
        @Bind(R.id.shop_addr)
        TextView shopAddr;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
